﻿using System;

namespace OpenSearch
{
    /// <summary>
    /// Common conversion routines for OpenSearch formats
    /// </summary>
    static public class Convert
    {
        /// <summary>
        /// Convert dateTime to standard Time Extension date / time format
        /// </summary>
        /// <param name="dateTime">DateTime to convert</param>
        /// <returns>DateTime in RFC3339 format, as required by Time Extension</returns>
        static public string DateTimeToString(DateTime dateTime)
        {
            if (dateTime.Kind == DateTimeKind.Unspecified)
            {
                return System.Xml.XmlConvert.ToString(dateTime, System.Xml.XmlDateTimeSerializationMode.Utc);
            }
            return System.Xml.XmlConvert.ToString(dateTime, System.Xml.XmlDateTimeSerializationMode.RoundtripKind);
        }
    }
}